<template>
    <div class="right-wrapper content-myTest page-lianxibaogao">
        <div class="container">
            <div class="row">
                <div class="box-title">
                    <p>练习类型：快速智能练习</p>
                    <p v-if="rows.length > 0">交卷时间：{{rows[0]['updated_time']}}</p>
                </div>
                <div class="box-cuodui">
                    <div class="secton-dadui">
                        <p>答对</p>
                        <p><span>{{rightCount}}</span>题</p>
                    </div>
                    <div class="secton-nandu">
                        <p>3.9</p>
                        <p>难度</p>
                    </div>
                </div>
                <div class="box-list">
                    <ul>
                        <li v-for="(item,ik) in rows" ><span :class="{'red':item.is_answer_right==0,'green':item.is_answer_right==1,'danshu':ik<9}"><b>{{ik+1}}</b></span></li>
                    </ul>
                </div>
                <div class="box-qingkuang">
                    <h3>考试情况</h3>
                    <div class="secton-line" v-for="(p,pk) in pointCategories">
                        <h4>{{p.prefix}}{{p.title}}</h4>
                        <p>{{p.prefix}}共{{pointCount[p.id] || 0}}题，答对{{pointRightCount[p.id] || 0}}题，正确率0% --</p>
                    </div>
                    <!--<div class="secton-line">-->
                        <!--<h4>政治</h4>-->
                        <!--<p>共2题，答对0题，正确率0%，用时2秒</p>-->
                    <!--</div>-->
                    <!--<div class="secton-line">-->
                        <!--<h4>经济</h4>-->
                        <!--<p>共5题，答对1题，正确率20%，用时12秒</p>-->
                    <!--</div>-->
                    <!--<div class="secton-line">-->
                        <!--<h4>管理</h4>-->
                        <!--<p>共5题，答对1题，正确率20%，用时12秒</p>-->
                    <!--</div>-->
                    <!--<div class="secton-line">-->
                        <!--<h4>人文科技</h4>-->
                        <!--<p>共5题，答对1题，正确率20%，用时12秒</p>-->
                    <!--</div>-->
                    <!--<div class="secton-line">-->
                        <!--<h4>法律</h4>-->
                        <!--<p>共5题，答对1题，正确率20%，用时12秒</p>-->
                    <!--</div>-->
                </div>
            </div>
        </div>
    </div>
</template>
<style>
    .red{
        background-color:red !important;
    }
    .green{
        background-color:forestgreen !important;
    }
</style>
<script>
    import http from "../../lib/http"
    import jquery from "../../lib/jquery"
    import tree from "../../lib/tree2"
    export default{
        data : function(){
            var params = this.$route.path.split("-")
            this.simu_id = params[1]
            return {
                rows : [],
                pointRightCount : {},
                pointCount : {},
                pointCategories : {},
                pointTreeCategories : {}
            }
        },
        computed : {
            rightCount : function () {
                var rc = 0,self = this,tc = {}
                for(var i=0,j=this.rows.length;i<j;i++){
                    var row = this.rows[i]
                    if(row.is_answer_right != "0"){
                        rc++
                        this.pointRightCount[row.pq_test_point_category_id] = this.pointRightCount[row.pq_test_point_category_id] || 0
                        this.pointRightCount[row.pq_test_point_category_id]++
                    }
                    this.pointCount[row.pq_test_point_category_id] = this.pointCount[row.pq_test_point_category_id] || 0
                    this.pointCount[row.pq_test_point_category_id]++
                    //final level -> top level plus
                    //得一层层往上加，需要一个point_category_id -> point_categorey_pid的阶梯链条，一直网上追溯
                }
//                var treeCount = function (data,pid) {
//                    if(!data.hasOwnProperty(pid)) return
//                    var childdata = data[pid] || []
//                    if(childdata.length) {
//                        for(var i, j = childdata.length; i < j; i++) {
//                            //tc[pid] = tc[pid] || {}
//                            //tc[pid]["pc"] += self.pointCount[childdata[i]['id']] * 1
//                            alert(childdata[i]['id'])
//                            //treeCount(data, childdata[i]['id'])
//                        }
//                    }
//                }
//                treeCount(self.pointTreeCategories,'0')
//                console.log(tc)
                return rc
            }
        },
        created : function(){
            this.getSimuTest()
            this.getPointCategories()
        },
        methods : {
            getSimuTest : function () {
                var self = this
                http.alive(this,function(){
                    http.get(self,"cs_test_libraries_item/simu/"+self.simu_id).then(function (res) {
                        self.loading = false
                        self.rows = res.data.data
                    })
                })
            },
            getTest : function () {

            },
            getPointCategories : function () {
                var self = this
                http.get(this,"point_categories").then(function (res) {
                    //console.log(res.data.data)
                    //self.pointCategories = res.data.data
                    self.pointCategories = tree.make(res.data.data,"pid",2)
                   // self.pointTreeCategories = tree.raw(res.data.data,"pid",0)
                    //console.log(ps)
                })
            }
        }
    }
</script>
